/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bus.service;

import java.util.List;

import com.thinkgem.jeesite.common.utils.EnumProperty;
import com.thinkgem.jeesite.common.utils.IdGen;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.bus.entity.Vaccine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.bus.entity.VaccineInfo;
import com.thinkgem.jeesite.modules.bus.dao.VaccineInfoDao;

/**
 * 疫苗详细信息Service
 * @author zhangxingliang
 * @version 2019-06-10
 */
@Service
@Transactional(readOnly = true)
public class VaccineInfoService extends CrudService<VaccineInfoDao, VaccineInfo> {

	@Autowired
	private VaccineInfoDao vaccineInfoDao;

	public VaccineInfo get(String id) {
		return super.get(id);
	}
	
	public List<VaccineInfo> findList(VaccineInfo vaccineInfo) {
		return super.findList(vaccineInfo);
	}
	
	public Page<VaccineInfo> findPage(Page<VaccineInfo> page, VaccineInfo vaccineInfo) {
		return super.findPage(page, vaccineInfo);
	}
	
	@Transactional(readOnly = false)
	public void save(VaccineInfo vaccineInfo) {
		super.save(vaccineInfo);
	}
	
	@Transactional(readOnly = false)
	public void delete(VaccineInfo vaccineInfo) {
		super.delete(vaccineInfo);
	}

	/**
	 * @author Zhang Xingliang
	 * @description 获取疫苗详情列表
	 * @date 19:56 2019/6/21
	 * @params [vaccineInfo]
	 * @return java.util.List<com.thinkgem.jeesite.modules.bus.entity.VaccineInfo>
	 **/
	public List<VaccineInfo> findVaccineInfoiList(VaccineInfo vaccineInfo) {
		return vaccineInfoDao.findVaccineInfoiList(vaccineInfo);
	}

	/**
	 * @author Zhang Xingliang
	 * @description 保存疫苗详情信息 TODO 优化成批量插入
	 * @date 9:14 2019/6/25
	 * @params [VaccineInfoList, vaccineId, entId, entHistoryId, isNewRecord]
	 * @return void
	 **/
	@Transactional(readOnly = false)
	public void save(List<VaccineInfo> VaccineInfoList,String vaccineId,String entId,String entHistoryId,boolean isNewRecord) {
		for (VaccineInfo vaccineInfo :  VaccineInfoList) {
			if(isNewRecord || StringUtils.isBlank(vaccineInfo.getId()) || "-1".equals(vaccineInfo.getId())){
				if(StringUtils.isNotBlank(vaccineInfo.getRemarks()) && EnumProperty.DataStatus.DELFLAG.getKey().equals(vaccineInfo.getRemarks())){
					continue;
				}
				vaccineInfo.setIsNewRecord(true);
				vaccineInfo.setId(IdGen.nextId());
			}
			if(StringUtils.isNotBlank(vaccineInfo.getRemarks()) && EnumProperty.DataStatus.DELFLAG.getKey().equals(vaccineInfo.getRemarks())){
				this.delete(vaccineInfo);
				continue;
			}
			vaccineInfo.setVaccineId(vaccineId);
			vaccineInfo.setEntId(entId);
			vaccineInfo.setEntHistoryId(entHistoryId);
			vaccineInfo.setStatus(EnumProperty.DataStatus.ABLE.getKey());
			this.save(vaccineInfo);
		}
	}

}